package com.yongbao.controller.wechat;

import com.yongbao.common.WebResponse;
import com.yongbao.common.annotation.WebAccess;
import com.yongbao.common.PageInfo;
import com.yongbao.model.request.DishOrderRequest;
import com.yongbao.model.request.manual.order.JoinOrderAddRequest;
import com.yongbao.model.request.manual.order.MainOrderAddRequest;
import com.yongbao.model.request.manual.order.NearbyOrderRequest;
import com.yongbao.model.vo.manual.NearbyOrderVO;
import com.yongbao.model.vo.manual.UserBookDetailVO;
import com.yongbao.service.DishOrderService;
import com.yongbao.model.vo.DishOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/wechat/dishOrder")
@Api(value = "【小程序】订单模块", tags = {"【小程序】订单模块"})
public class WechatDishOrderController {
    @Autowired
    private DishOrderService dishOrderService;

    @WebAccess(login = true)
    @ApiOperation(value = "根据主键查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<DishOrderVO> getByKey(HttpServletRequest request, @PathVariable("id") long id) {
        return WebResponse.build(dishOrderService.getByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<DishOrderVO>> pageQuery(@RequestBody DishOrderRequest request) {
        return WebResponse.build(dishOrderService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("列表查询")
    @PostMapping("/listQuery")
    public WebResponse<List<DishOrderVO>> listQuery(@RequestBody DishOrderRequest request) {
        return WebResponse.build(dishOrderService.listQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增【主订单】")
    @PostMapping("/mainOrderAdd")
    public WebResponse<Boolean> mainOrderAdd(@Valid @RequestBody MainOrderAddRequest request) {
        return WebResponse.build(dishOrderService.mainOrderAdd(request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增【拼团】")
    @PostMapping("/joinGroupAdd")
    public WebResponse<Boolean> joinGroupAdd(@Valid @RequestBody JoinOrderAddRequest request) {
        return WebResponse.build(dishOrderService.joinGroupAdd(request));
    }

    @WebAccess(login = true)
    @ApiOperation("查询附近订单")
    @PostMapping("/nearbyOrder")
    public WebResponse<NearbyOrderVO> nearbyOrder(@Valid @RequestBody NearbyOrderRequest request) {
        return WebResponse.build(dishOrderService.nearbyOrder(request));
    }

    @WebAccess(login = true)
    @ApiOperation("查询预定详情")
    @PostMapping("/bookDetail")
    public WebResponse<List<UserBookDetailVO>> bookDetail() {
        return WebResponse.build(dishOrderService.bookDetail());
    }

}
